import { ARR_METHODS } from "./config";
import observerArr from './observerArr';

var originArrMethods = Array.prototype,
    arrMthods = Object.create(originArrMethods);

ARR_METHODS.forEach(function (m) {
    arrMthods[m] = function () {
        var args = Array.prototype.slice.call(arguments),
            rt = originArrMethods[m].apply(this, args);

        // 把新数组或者是新增加的内容也要进行观察一次 绑定上响应式数据
        var newArr;

        switch (m) {
            case "push":
            case "unshift":
                newArr = args;
                break;
            case "splice":
                newArr = args.slice[2];
                break;
            default:
                break;
        }

        newArr && observerArr(newArr);

        return rt;
    }
})

export {
    arrMthods
}